# Cecilia Mo
# March 13, 2017
# Replication File for Political Behavior
# Figure 2 for Study 1

library(foreign)

####Error Bar Construction###
error.bar <- function(x, y, upper, lower=upper, length=0.05,...){
  if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != length(upper))
    stop("vectors must be same length")
  arrows(x,y+upper, x, y-lower, angle=90, code=3, length=length, ...)
}

#####Graph Figure 2#####
rawdata1 <- matrix(c(.2587601, .3130435, .1263441, .2011662 ,  .230563 ,  .2803468 ),2,3)
ee1 <- matrix(c(.02648364, .02908291, .02006376, .02521413,  .02540152, .02812874),2,3)

barx1 <- barplot(rawdata1, beside=T, names.arg=c("Risky Job for Oneself","Risky Job for Child","Lottery Participation"), ylim=c(0, 0.37), xpd=F, col=c("gray75", "gray45", "gray75", "gray45", "gray75", "gray45"),cex.names=1, axis.lty=1,ylab="Risky Option Chosen", font.lab=2, cex=1, cex.main=1, cex.lab=1) 
legend("topright",pch=c(15,15,15,15,15,15), col=c("gray75", "gray45", "gray75", "gray465", "gray75", "gray45"), c("Control","Relative Deprivation Prime"), text.width=c(3.25,3.25), cex=0.9)
error.bar(barx1,rawdata1,ee1)
